
package com.gitee.flow.service;

import com.gitee.flow.dao.HiTaskinstDao;
import com.gitee.flow.entity.HiTaskinstEntity;
import com.gitee.jmash.core.orm.cdi.JpaTenantService;
import com.gitee.jmash.core.orm.jpa.TenantEntityManager;
import com.gitee.jmash.core.orm.tenant.TenantService;
import com.gitee.jmash.core.transaction.JakartaTransaction;
import jakarta.enterprise.inject.Typed;
import jakarta.enterprise.inject.spi.CDI;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.transaction.Transactional;
import jakarta.transaction.Transactional.TxType;
import jakarta.validation.executable.ValidateOnExecution;
import java.util.List;
import jmash.flow.protobuf.HiTaskinstReq;

/**
 *  act_hi_taskinst读服务.
 *
 * @author <a href="mailto:service@crenjoy.com">crenjoy</a>
 */
@Typed(HiTaskinstRead.class)
@Transactional(TxType.SUPPORTS)
@JpaTenantService
@ValidateOnExecution
public class HiTaskinstReadBean implements HiTaskinstRead, JakartaTransaction {

  protected TenantEntityManager tem = new TenantEntityManager();

  protected HiTaskinstDao hiTaskinstDao = new HiTaskinstDao(tem);

  @PersistenceContext(unitName = "ReadFlow")
  public void setEntityManager(EntityManager entityManager) {
    this.tem.setEntityManager(entityManager,false);
  }
	
  @Override
  public EntityManager getEntityManager() {
    return this.tem.getEntityManager();
  }

  @Override
  @SuppressWarnings("unchecked")
  public <T extends TenantService> T setTenant(String tenant) {
    this.tem.setTenant(tenant);
    return (T) this;
  }
  
  @Override
  public void setTenantOnly(String tenant) {
     this.tem.setTenantOnly(tenant);
  }

  @Override
  public String getTenant() {
    return this.tem.getTenant();
  }

  @Override
  public HiTaskinstEntity findById(String entityId) {
    return hiTaskinstDao.find(entityId);
  }

  @Override
  public List<HiTaskinstEntity> findListByReq(HiTaskinstReq req) {
    return hiTaskinstDao.findListByReq(req);
  }
  
  @Override
  public void close() throws Exception {
    CDI.current().destroy(this);
  }
}
